<template>
  <div class="article-item van-hairline--bottom">
    <van-popup v-model="show" round>
      <van-cell-group>
        <van-cell @click="dislike(article.art_id)" title="不感兴趣" clickable />
        <van-cell title="反馈垃圾内容" is-link  />
        <van-cell title="拉黑作者" clickable />
      </van-cell-group>
    </van-popup>
    <div class="article" @click.stop="detail(article.art_id)">
      <p class="title" :class="{ w66: article.cover.type === 1 }">
      {{ article.title }}
    </p>
    <img
      class="img"
      :src="item"
      alt=""
      v-for="(item, index) in article.cover.images"
      :key="index"
    />
    <div class="info">
      <span>{{ article.aut_name.substring(0, 5) }}</span>
      <span>17评论</span>
      <span>1天前</span>
      <geek-icon @click.native.stop="showPopup" v-if="isToken" name="esay-close"></geek-icon>
    </div>
    </div>
  </div>
</template>

<script>
import { dislikeArticle } from '@/api/article'
import to from 'await-to-js'
import { Toast } from 'vant'
import { getToken } from '@/utils/storage'
export default {
  data () {
    return {
      show: false,
      isToken: false
    }
  },
  props: {
    article: {
      type: Object,
      required: true
    }
  },
  created () {
    this.isToken = getToken()
  },
  methods: {
    showPopup () {
      this.show = true
    },
    async dislike (id) {
      const [err] = await to(dislikeArticle({ target: id }))
      if (err) return Toast.fail(err.response.data.message)
      Toast.success('操作成功')
      this.show = false
      this.$emit('dislike', id)
    },
    detail (id) {
      this.$router.push(`/article/${id}`)
    }
  }
}
</script>

<style lang="less">
.article-item .article {
  padding: 10px 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .title {
    width: 100%;
    margin: 0;
    line-height: 22px;
    font-size: 16px;
    color: #333;
    margin-bottom: 8px;
    max-height: 44px;
    &.w66 {
      width: 66%;
    }
  }
  .img {
    width: 112px;
    height: 74px;
    border-radius: 4px;
    margin-bottom: 8px;
  }
  .info {
    width: 100%;
    color: #a5a6ab;
    font-size: 12px;
    position: relative;
    span {
      margin-right: 12px;
    }
    .geek-icon {
      float: right;
      font-size: 14px;
    }
  }
}
.van-popup--center{
  width: 328px;
}
</style>
